<html><head><title>Import : EndImport</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="5">Import : EndImport</font></b></p>

<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#006666">Import</font></b> "Filename"
  FunctionName.&#060;type&#062;(&#060;parameter&#062;, [, &#060;parameter&#062; [= DefaultValue]...]) [As "SymbolName"]
  ...
  VariableName.&#060;type&#062; [As "SymbolName"]
<b><font color="#006666">EndImport</font></b>
</font></pre></blockquote>
<b>Description</b><br><blockquote>


For advanced programmers. <b><font color="#006666">Import</font></b> : <b><font color="#006666">EndImport</font></b> allows to easy declare external functions and variables from 
a library (.lib) or an object (.obj) file. 
<br>
<br>
Once declared, the imported functions are directly available 
for use in the program, like any other commands. The compiler doesn't check if the functions really exists 
in the imported file, so if an error occurs, it will be reported by the linker. 
<br>
<br>
This feature can replace the <a href="../library/openlibrary.html">OpenLibrary()</a>/<a href="../library/callfunction.html">CallFunction()</a> 
sequence as it has some advantages: type checking is done, number of 
parameters is validated. Unlike CallFunction(), it can deal with double, float and quad 
without any problem. 
<br>
<br>
The last parameters can have a default value (need to be a constant 
expression), so if these parameters are omitted when the function is called, the default value will be used. 
<br>
<br>
By default the imported function symbol is 'decorated' in the following way: _FunctionName@callsize. That 
should work for most of the functions which use the standard call convention (stdcall). If the library is a C one, and 
the function are not stdcall, the <b><font color="#006666">ImportC</font></b> variant should be used instead. In this case, the default function 
symbol is decorated like: _FunctionName. 
<br>
<br>
The <a href="../reference/pseudotypes.html">pseudotypes</a> can be used for the parameters, but not for the returned 
value. 
@remaks
On x64, there is only one calling convention, so <b><font color="#006666">ImportC</font></b> will be behave the sames as <b><font color="#006666">Import</font></b>. 

</blockquote><p><b>Example</b></p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Import</font></b> "User32.lib"
   
    <font color="#006666">; No need to use 'As' as PureBasic decorates the function correctly</font>
    <font color="#006666">; We also define the 'Flags' as optional, with a default value of 0 (when omitted)</font>
    <font color="#006666">;</font>
<font color="#006666">    MessageBoxA</font>(Window.i, Body$, Title$, Flags.i = 0)
    
    <font color="#006666">; This time PureBasic can't find it alone as the function </font>
    <font color="#006666">; name isn't the same than the one used by the symbol</font>
    <font color="#006666">;</font>
<font color="#006666">    MsgBox</font>(Window.i, Body$, Title$, Flags.i) <b><font color="#006666">As</font></b> "_MessageBoxA@16"
                                                   
  <b><font color="#006666">EndImport</font></b>
  
<font color="#006666">  MessageBoxA</font>(0, "Hello", "World") <font color="#006666">; We don't specify the flags</font>
<font color="#006666">  MsgBox</font>(0, "Hello", "World 2", 0)
    
</font></pre>


</blockquote><p><b>Example:</b> With pseudotypes</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Import</font></b> "User32.lib"
   
    <font color="#006666">; We use the 'p-unicode' pseudotype for the string parameters, as</font>
    <font color="#006666">; MessageBoxW() is an unicode only function. The compiler will </font>
    <font color="#006666">; automatically converts the strings to unicode when needed.</font>
    <font color="#006666">;</font>
<font color="#006666">    MessageBoxW</font>(Window.l, Body.p-unicode, Title.p-unicode, Flags.l = 0)
                                                  
  <b><font color="#006666">EndImport</font></b>
  
  <font color="#006666">; It will work correctly in ascii and in unicode mode, even if the API is unicode</font>
  <font color="#006666">; only as the compiler will take care of the conversion itself.</font>
  <font color="#006666">;</font>
<font color="#006666">  MessageBoxW</font>(0, "Hello", "World")
    
</font></pre>



</body></html>